package cn.tedu.egmvc3.controller;

import cn.tedu.egmvc3.mapper.EmpMapper;
import cn.tedu.egmvc3.pojo.dto.EmpControllerDTO;
import cn.tedu.egmvc3.pojo.emtity.Emp;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("emp/")
public class EmpController {
    @Autowired
    private EmpMapper empMapper;
    @RequestMapping("insert")

    public String insertEmp(EmpControllerDTO empControllerDTO) {
        Emp emp = new Emp();
        BeanUtils.copyProperties(empControllerDTO,emp);
        empMapper.insertEmp(emp);
        return "添加成功";
    }
    @RequestMapping("select")
    public List<Emp> selectEmpList() {
        return empMapper.selectEmpList();
    }
    @RequestMapping("update")
    public String UpdateEmp(Emp emp){
        empMapper.UpdateEmp(emp);
        return "修改成功";
    }
    @GetMapping("delete")
    public String deleteEmpById(Long id){
        empMapper.deleteEmpById(id);
        return "删除成功";
    }
}
